Soru & Cevap

OpenGL ES hatası

14.05.2020 - 05:47

Merhaba arkadaşlar, canvas a metin yazarken önce bitmape dönüştürüp sonra yazdırıyorum, ancak resim kalitesi düşük çıkıyor, OpenGL ES kullandım ancak bu sefer aşağıda bulunan hatayı verdi, neden veriyor bu hatayı, veya nasıl kullanabilirim burada OpenGL ES yi, bilen varsa yardımcı olursa sevinirim.

 

Kullandığım Kod:

private Bitmap Text(){
    Bitmap image = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    int[] textures = new int[1];
    Canvas canvas = new Canvas(image);
    if (drawable != null) {
        drawable.setBounds(realBounds);
        drawable.draw(canvas);
    }

    if (textRect.width() == getWidth()) {
        int dy = getHeight() / 2 - staticLayoutText.getHeight() / 2;
        // center vertical
        canvas.translate(0, dy);
    } else {
        int dx = textRect.left;
        int dy = textRect.top + textRect.height() / 2 - staticLayoutText.getHeight() / 2;
        canvas.translate(dx, dy);
    }

    staticLayoutShadow.draw(canvas);
    staticLayoutOutline.draw(canvas);
    staticLayoutText.draw(canvas);
    
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, image, 0);

    image.recycle();

    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    
    return image;
}

@Override
public void draw(@NonNull Canvas canvas) {
    Matrix matrix = getMatrix();
    canvas.save();
    canvas.concat(matrix);
    paint = new Paint();
    paint.setAntiAlias(true);
    if (mode != null)
        paint.setXfermode(new PorterDuffXfermode(mode));
    canvas.drawBitmap(Text(), null, realBounds, paint);
    canvas.restore();
}

Verdiği Hata:

E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
D/AndroidRuntime: Shutting down VM
    
    
    --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.phonenix.stickerview, PID: 18041
    java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@eb81b74
        at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1271)
        at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
        at com.phonenixi.sticker.TextSticker.draw(TextSticker.java:175)
        at com.phonenixi.sticker.StickerView.drawStickers(StickerView.java:278)
        at com.phonenixi.sticker.StickerView.dispatchDraw(StickerView.java:271)
        at android.view.View.buildDrawingCacheImpl(View.java:16576)
        at android.view.View.buildDrawingCache(View.java:16438)
        at android.view.View.draw(View.java:17068)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at android.view.View.updateDisplayListIfDirty(View.java:16257)
        at android.view.View.draw(View.java:17076)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at android.view.View.updateDisplayListIfDirty(View.java:16257)
        at android.view.View.draw(View.java:17076)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at android.view.View.updateDisplayListIfDirty(View.java:16257)
        at android.view.View.draw(View.java:17076)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at android.view.View.updateDisplayListIfDirty(View.java:16257)
        at android.view.View.draw(View.java:17076)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at android.view.View.updateDisplayListIfDirty(View.java:16257)
        at android.view.View.draw(View.java:17076)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3890)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3676)
        at com.android.internal.policy.DecorView.dispatchDraw(DecorView.java:792)
        at android.view.View.draw(View.java:17338)
        at com.android.internal.policy.DecorView.draw(DecorView.java:778)
        at android.view.View.updateDisplayListIfDirty(View.java:16265)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:661)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:667)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:775)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:3188)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2981)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2569)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1462)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6965)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:907)
        at android.view.Choreographer.doCallbacks(Choreographer.java:709)
        at android.view.Choreographer.doFrame(Choreographer.java:644)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:893)
        at android.os.Handler.handleCallback(Handler.java:836)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6251)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
D/OpenGLRenderer: ~CanvasContext() 0x7d84e7b800

Kodlarından yararlandığım site:https://arm-software.github.io/opengl-es-sdk-for-android/high_quality_text.html

12 Görüntülenme

0 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.